package com.gexiaobao.pigeon.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.gexiaobao.pigeon.R

/**
 * @author:hxw
 * @date  :2022/12/8
 * @desc  :
 */
class RxDialogPlayBack(context: Context?) : RxDialog(context!!) {

    private lateinit var cancelView: AppCompatButton
    private lateinit var titleView: AppCompatTextView
    private lateinit var tvGatherPlayBack: AppCompatTextView
    private lateinit var tvCarPlayBack: AppCompatTextView
    private lateinit var tvHomingPlayBack: AppCompatTextView
    private lateinit var viewGather: View
    private lateinit var viewCar: View
    private lateinit var viewHoming: View

    init {
        initView()
    }

    @SuppressLint("MissingInflatedId")
    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_play_back, null)
        cancelView = dialogView.findViewById(R.id.cancelView)
        tvGatherPlayBack = dialogView.findViewById(R.id.tvGatherPlayBack)
        titleView = dialogView.findViewById(R.id.tvDialogTitle)
        tvCarPlayBack = dialogView.findViewById(R.id.tvCarPlayBack)
        tvHomingPlayBack = dialogView.findViewById(R.id.tvHomingPlayBack)
        viewGather = dialogView.findViewById(R.id.viewGather)
        viewCar = dialogView.findViewById(R.id.viewCar)
        viewHoming = dialogView.findViewById(R.id.viewHoming)

        cancelView.setOnClickListener {
            dismiss()
        }
        setContentView(dialogView)
    }

    fun setHideGather(isGone: Boolean) {
        tvGatherPlayBack.isGone = isGone
        viewGather.isGone = isGone
    }

    fun setHideCar(isGone: Boolean) {
        tvCarPlayBack.isGone = isGone
        viewCar.isGone = isGone
    }

    fun setHideHoming(isGone: Boolean) {
        tvHomingPlayBack.isGone = isGone
        viewHoming.isGone = isGone
    }

    fun setGatherListener(listener: View.OnClickListener?) {
        tvGatherPlayBack.setOnClickListener(listener)
    }

    fun setCarListener(listener: View.OnClickListener?) {
        tvCarPlayBack.setOnClickListener(listener)
    }

    fun setHomingListener(listener: View.OnClickListener?) {
        tvHomingPlayBack.setOnClickListener(listener)
    }

    fun setTitle(titleStr: String) {
        if (titleStr.isEmpty()) {
            titleView.visibility = View.GONE
            return
        }
        titleView.text = titleStr
        titleView.visibility = View.VISIBLE
    }
}